<?php

namespace App\Http\Controllers\user;

use App\Dao\BillsDao;
use App\Dao\BusinessesDao;
use App\Dao\CommonDao;
use App\Dao\CursorsDao;
use App\Dao\LineUpPriceDao;
use App\Dao\SbillsDao;
use App\Dao\UsersDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;
use App\Services\OssServices;
use App\Services\SmsServices;
use Illuminate\Support\Facades\DB;

class CommonController extends BaseController
{
    public function test()
    {

    }
    public function cursors(): array
    {
        return Code::message('',200,CursorsDao::cursorsWithNoPage(['show'=>1]));
    }

    /**
     * @throws SysExceptions
     */
    public static function sms_send(): array
    {
        $params = request()->all();
        CommonDao::sms_send($params);
        return Code::message('',200);
    }

    public function moneys_logs(): array
    {
        $params = request()->all();
        $params['user_id'] = getUserToken();
        return Code::message('',200,BillsDao::moneysLog($params));
    }
    public function settings()
    {
        return Code::message('',200,[
            'cphone'=>'188588888888'
        ]);
    }

    public function xiaofei_Log(): array
    {
        $params = request()->all();
        $params['user_id'] = getUserToken();
        return Code::message('',200,BillsDao::xiaoFeiLog($params));
    }




    public function shops(): array
    {
        return Code::message('',200,BusinessesDao::businesses([
            'show'=>1
        ]));
    }
    public function shopInfo(): array
    {
        return Code::message('',200,BusinessesDao::info([
            'show'=>1,
            'businesses_id'=>request('businesses_id')
        ]));
    }

    public function file_up(): array
    {
        ini_set('memory_limit','2048M');
        set_time_limit(0);
        $filePath = $_FILES["file"]["tmp_name"];
        $ext = substr($_FILES['file']['name'],strrpos($_FILES['file']['name'],'.')+1); // 上传文件后缀
        $accept = request('accept');
//        if(!in_array(strtolower($ext),$this->arr_ext[$accept])){
//            return Code::message('文件格式不正确!!',301);
//        }
        $object=date('YmdHis').'-'.time().'.'.$ext;
        $oss = new OssServices();
        $url = $oss->upload($object,$filePath);
        return Code::message('',200,[
            'src'=>$url
        ]);

    }
}
